# -*- coding: utf-8 -*-
# @Time     : 2021/11/26 16:08
# @Author   : wljess
# @File     : 权限验证.py
# @Describe : 
# @Software : PyCharm


user_list = [
  {'name': 'ad1', 'passwd': '123'},
  {'name': 'ad2', 'passwd': '123'},
  {'name': 'ad3', 'passwd': '123'},
  {'name': 'ad4', 'passwd': '123'}
]


def auth(func):
    def wrapper(*args, **kwargs):
        param = args[0]
        if param != "index.html":
            username = input("请输入用户名：")
            pwd = input("请输入用户密码：")

            # 检查输入的用户名和密码是否正确
            for user in user_list:
                if username == user['name'] and pwd == user['passwd']:
                    if param in ("shop.html", "root"):
                        print("登录成功！！！")
                        return func(*args, **kwargs)

                    raise ValueError("传入参数错误...")

            raise ValueError("输入的用户名和密码不存在，请进入注册页面注册用户...")

        return func(*args, **kwargs)

    return wrapper


@auth
def index(url):
    print(f"主页url:{url} 欢迎来到主页...")


@auth
def home(name):
    print("欢迎回家:%s" % name)


@auth
def shop(url):
    print(f'购物页面路由信息：{url},购物车里有奶茶, 妹妹, 娃娃')


if __name__ == '__main__':
    index('index.html')

    home('root')

    shop('shop.html')
    shop('shop1.html')

